package org.jeecg.modules.audit.service.impl;

import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.jeecg.modules.audit.service.AuditLiveApplyService;
import org.jeecg.modules.live.entity.LiveApply;
import org.jeecg.modules.live.entity.LiveInfo;
import org.jeecg.modules.live.mapper.LiveApplyMapper;
import org.jeecg.modules.live.mapper.LiveInfoMapper;
import org.jeecg.modules.live.service.ILiveApplyService;
import org.jeecg.modules.live.service.ILiveInfoService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @Description: 直播申请
 * @Author: jeecg-boot
 * @Date:   2020-05-07
 * @Version: V1.0
 */
@Service
public class AuditLiveApplyServiceImpl extends ServiceImpl<LiveApplyMapper, LiveApply> implements AuditLiveApplyService {

    @Autowired
    private LiveApplyMapper liveApplyMapper;;
    @Autowired
    private LiveInfoMapper liveInfoMapper;
    @Autowired
    private ILiveApplyService liveApplyService;
    @Autowired
    private ILiveInfoService liveInfoService;

    @Override
    @Transactional
    public void auditLiveApproved(LiveApply liveApply, LiveInfo liveInfo) {
        //把之前的都清除掉
        liveInfoMapper.deleteUserLive(liveInfo.getUserId());
        liveApplyMapper.updateById(liveApply);
        liveInfoMapper.insert(liveInfo);
    }

    @Override
    @Transactional
    public void auditBatchLiveApproved(List<LiveApply> liveApplyList, List<LiveInfo> liveInfoList) {
        liveApplyService.updateBatchById(liveApplyList);
        liveInfoService.updateBatchById(liveInfoList);
    }
}
